
# Uganda ------------------------------------------------------------------

# Uganda 1

m1 <- lm(police_satisfactory ~ female + as.factor(tc), data = ug1_no_imp)

# Uganda 2
m2 <- lm(police_satisfactory ~ female + as.factor(tc_id), data = ug2_no_imp)

# Uaganda 3
m3 <- lm(police_not_bribe ~ female + as.factor(tc_id), data = ug3_no_imp)


# tan_no_impzania ----------------------------------------------------------------
# Information on gender is missing for two respondents in the first Tanzania wave
# Hence, these respondents are dropped from this analysis.
m4 <- lm(police_satisfactory ~ female + as.factor(village), data = tan_no_imp)

# South Africa ------------------------------------------------------------

m5 <- lm(trust_police ~ female + community, data = sa_no_imp)

# afro_no_impbarometer -----------------------------------------------------------

m6 <- lm(trust_police ~ female + region, data = afro_no_imp)

m7 <- lm(no_police_corrupt ~ female + region, data = afro_no_imp)

m8 <- lm(easy_obtain_police_service ~ female + region, data = afro_no_imp)

# Get HC1 robust standard errors from estimatr package
ses<- starprep(m1,
               m2,
               m3,
               m4,
               m5,
               m6,
               m7,
               m8, stat = "std.error",se_type = "HC1")

pvals<- starprep(m1,
                 m2,
                 m3,
                 m4,
                 m5,
                 m6,
                 m7,
                 m8, stat = "p.value",se_type = "HC1")


sink("04_manuscript/tables/views_police_gender_no_imp.tex")
stargazer(
  m1,
  m2,
  m3,
  m4,
  m5,
  m6,
  m7,
  m8,
  se = ses,
  p = pvals,
  # type = "text",
  omit.stat = c("rsq","f","ser"), 
  keep = "female",
  column.labels = c("Uganda 1","Uganda 2","Uganda 3","Tanzania 1","South Africa","Afrobar.", "Afrobar.","Afrobar."),
  #column.separate = c(1,1,1,1,1,3),
  #table.layout = "=cd#-t-as=n",
  covariate.labels = "Woman",
  add.lines = list(
    c(
      "Avg. men",
      round(c(with(ug1_no_imp,mean(police_satisfactory[female == 0],na.rm = TRUE)),
              with(ug2_no_imp,mean(police_satisfactory[female == 0],na.rm = TRUE)),
              with(ug3_no_imp,mean(police_not_bribe[female == 0],na.rm = TRUE)),
              with(tan_no_imp,mean(police_satisfactory[female == 0],na.rm = TRUE)),
              with(sa_no_imp,mean(trust_police[female == 0],na.rm = TRUE)),
              with(afro_no_imp,mean(trust_police[female == 0],na.rm = TRUE)),
              with(afro_no_imp,mean(no_police_corrupt[female == 0],na.rm = TRUE)),
              with(afro_no_imp,mean(easy_obtain_police_service[female == 0],na.rm = TRUE)))
              ,2)),
    c("Area FE",rep("Yes",8)),
    c("Outcome",c("Satisf.","Satisf.","No Bribe","Satisf.","Trust","Trust","Not Corrupt", "Easy access"))
  ),
  no.space = TRUE,dep.var.caption = "Police Approval",float = F,
  
  dep.var.labels.include = FALSE
)
sink()

rm(m1,
   m2,
   m3,
   m4,
   m5,
   m6,
   m7,
   m8,ses,pvals)




